package com.billionsfinance.hessian.db.impl;

import com.billionsfinance.hessian.core.ServerInfo;
import com.billionsfinance.hessian.db.HessianServerDao;
import com.billionsfinance.hessian.db.core.StrategyBaseDao;

import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

/**
 * @author WeiHui.Zhang
 * @version V1.00
 * @fileName: HessianServerDaoImpl.java
 * @date 2016年7月25日 下午5:43:47
 */
public class HessianServerDaoImpl extends StrategyBaseDao implements HessianServerDao {

	@Override
	public List<ServerInfo> findAll() {
		String sql = "select * from Hessian_server;";
		PreparedStatement pstmt = execQuery(sql);
		ResultSet rs = null;
		List<ServerInfo> infos = null;
		if (pstmt != null) {
			infos = new ArrayList<>();
			try {
				rs = pstmt.executeQuery();
				while (rs.next()) {
					ServerInfo tempInfo = new ServerInfo();
					tempInfo.setAppCode(rs.getString("APP_CODE"));
					tempInfo.setAccessPath(rs.getString("ACCESS_PATH"));
					tempInfo.setInterfaceName(rs.getString("INTERFACE_NAME"));
					tempInfo.setServiceClassName(rs.getString("SERVICE_CLASS_NAME"));
					infos.add(tempInfo);
				}
			} catch (SQLException e) {
				LOGGER.error("执行出错" + sql, e);
			} finally {
				closeConn(pstmt, rs);
			}
		}
		return infos;
	}

}